// 负责和首页进行交互
var Movie = require('../models/movie')
var Category = require('../models/category')

exports.new = function (req, res) {
   // 后台的分类录入页面
    res.render('category_admin', {
        title: 'imooc 后台的分类录入页面',
        category: {}
    })

}
exports.save = function (req, res) {
    var _category = req.body.category
    var category = new Category(_category)
    category.save(function (err, category) {
        if (err) {
            console.log(err)
        }
        res.redirect('/admin/category/list')

    })
}
// userlist page
exports.list = function (req, res) {
     Category.fetch(function (err, categories) {
        if (err) {
            console.log(err)
        }
        res.render('categorylist', {
            title: 'imooc 分类列表页',
            categories: categories
        })
    })
}